﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using  Pout_Porri.Objects.Interface;

namespace Pout_Porri.Objects
{
    abstract class MovableGameEntity : AnimatedGameEntity, IGameEntity
    {
        /// <summary>
        /// The velocity for move
        /// </summary>
        protected Vector2 velocity;
        /// <summary>
        /// The velocity for move
        /// </summary>
        public Vector2 Velocity
        {
            get { return velocity; }
            set { velocity = value; }
        }

        private float maxVelocityX = 5;
        public float MaxVelocityX
        {
            get { return maxVelocityX; }
            set { maxVelocityX = value; }
        }

        private float defaultVelocityX;
        public float DefaultVelocityX
        {
            get { return defaultVelocityX; }
            set { defaultVelocityX = value; }
        }

        private float accelerationX;
        public float AccelerationX
        {
            get { return accelerationX; }
            set { accelerationX = value; }
        }


        /// <summary>
        /// a direction  to move
        /// </summary>
        protected Vector2 direction;
        /// <summary>
        /// a direction  to move
        /// </summary>
        public Vector2 Direction
        {
            get { return direction; }
            set { direction = value; }
        }

        protected bool isAnimated;

        //public float scale = 1.0f;

        /// <summary>
        /// Constructors
        /// </summary>
        /// <param name="image">an image</param>
        /// <param name="position">A position</param>
        /// <param name="frameSize">The width and height of the frame</param>
        /// <param name="velocity">A velocity</param>
        /// <param name="isAnimated">Check if this object is animated</param>
        public MovableGameEntity(Texture2D image, Vector2 position, Vector2 velocity, bool isAnimated)
            : base(image, position)
        {
            this.direction = Vector2.Zero;
            this.velocity = velocity;
            this.isAnimated = isAnimated;
        }

        /// <summary>
        /// Moves the GameEntity on especified direction
        /// </summary>
        protected virtual void applyMovement()
        {
            this.position += velocity * direction;
        }


        public override void draw(SpriteBatch spriteBatch)
        {
            if (isAnimated)
            {
                base.draw(spriteBatch);
            }
            else
            {
                spriteBatch.Draw(this.getImage(), this.position + Offset, null, Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, zOrder);
                //spriteBatch.Draw(this.getImage(),this.CollisionRect, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 0f);
                
                //todo colocar a versao 5 override do draw, está no 6, com vector2 position no segundo parametro e escala no antepenultimo
            }
        }

    }
}
